clear all
set more off
set mem 100m
tempfile temp

/* 

This dofile creates voting variables using raw data from ENAHO's module on democracy  (gobernabilidad democracia y transparencia, modulo 85)


*/

local data ../data/enaho
local working ../working

** 2007-2011
forvalues y = 2007/2011 {
	use `data'/`y'/enaho01b-`y'-1, clear

	gen year = `y'
	keep conglome vivienda hogar codperso year p15 p16 p17 p18
	tab p15
	tab p16 
	tab p17
	
	drop if p17 == 1

	recode p15 (1 = 1) (2 = 0) , gen(voted)
	recode p16 (1 = 0) (2 = 1) (3 = 0), gen(voted_blank)
	recode p16 (1 = 0) (2 = 0) (3 = 1), gen(voted_null)	
	recode p18 (1 = 1) (2 3 = 0), gen(vote_matters)
	gen voted_protest = voted_blank + voted_null
	
	destring conglome vivienda hogar codperso, replace
	keep conglome vivienda hogar codperso year vote*
	
	save dem_`y', replace
}

use dem_2007, clear
forvalues x = 2008/2011 {
	append using dem_`x'
}	

forvalues x = 2007/2011 {
	erase dem_`x'.dta
}	

** SAVE
compress
save `working'/voting, replace

